package com.weekdo.moviecomic;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.Shader;
import android.util.Log;
import android.widget.ImageView;

public class MirrorImageView extends ImageView {
	Paint m_paint;
	
	int viewWidth;
	int viewHeight;
	int imageWidth;
	int imageHeight;
	int imageScaledHeight;
	int topOffset;
	
	public MirrorImageView(Context context, int screenWidth, int screenHeight, int comicWidth, int comicHeight) {
		super(context);

		this.imageWidth = comicWidth;
		this.imageHeight = comicHeight;
		this.viewWidth = screenWidth;
		this.viewHeight = screenHeight;
		this.imageScaledHeight = this.imageHeight*this.viewWidth/this.imageWidth;
		this.topOffset = (int) ((this.viewHeight-imageScaledHeight*(1+ComicView.shadowPercent))/2);

		m_paint = new Paint(Paint.ANTI_ALIAS_FLAG);
		LinearGradient lg = new LinearGradient(0, imageScaledHeight+topOffset, 0, this.viewHeight, 0x50ffffff, 0x00000000, Shader.TileMode.CLAMP);
		m_paint.setShader(lg);
		m_paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));

	}

	@Override
	protected void onDraw(Canvas canvas)
	{
		Rect rect = canvas.getClipBounds();
		

		canvas.save();
		canvas.scale(1.0f, -1.0f);
		canvas.translate(0f, -(imageScaledHeight+imageScaledHeight+topOffset));
		super.onDraw(canvas);
		canvas.restore();

		canvas.drawRect(0, rect.bottom-150, rect.right, rect.bottom, m_paint);
		
		canvas.save();
		canvas.translate(0f, topOffset);
		super.onDraw(canvas);
		canvas.restore();

	}
}
